package com.team.arms.political.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.team.arms.common.ry.core.domain.AjaxResult;
import com.team.arms.political.domain.PoliReviewInfo;
import com.team.arms.political.domain.vo.Polialrvo;
import com.team.arms.political.mapper.PoliReviewInfoMapper;
import com.team.arms.political.service.PoliReviewInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Author huazige
 * @Date 2022/5/9 15:27
 * @Version 1.0
 */
@RequestMapping("/politialready")
@RestController
@CrossOrigin
@Api(tags = "政治考核-已政审")
public class Political_already {
    /**
     * 查询所有已政审的信息
     */

    @Autowired
    PoliReviewInfoService poliReviewInfoService;
    @Resource
    PoliReviewInfoMapper poliReviewInfoMapper;


    @ApiOperation("获取所有信息")
//    @Log(title = "政审信息", businessType = BusinessType.)
    @GetMapping(value = "/getpol")
    public AjaxResult selectpltc() {
        List<Polialrvo> list = poliReviewInfoMapper.selectalready();
//
        if (list!=null){
            return AjaxResult.success("查询成功",list) ;
        }
        else {
            return AjaxResult.error("查询失败");
        }


    }

    @ApiOperation(value = "姓名查找")
    @PostMapping("/find")
    //
//    三张表的数据，删除的时候，直接这三个都删除
    public AjaxResult find( @RequestParam("name")String name) {
        //也可以直接从redis缓冲中去调用一个foreach循环拿到对应name的数据
        QueryWrapper<PoliReviewInfo> wrapper = new QueryWrapper();
        wrapper.eq("name",name);
        List<Polialrvo> list = poliReviewInfoMapper.selectpolialrvo(name);
        if (list.size()>0){
            return AjaxResult.success("姓名查找成功",list);
        }else {
            return    AjaxResult.success("没有找到该人已政审信息");
        }

    }

    @ApiOperation("导出所有已政审的信息")
    @GetMapping("/exportexc")
    public void export(HttpServletResponse response)
    {
        List<Polialrvo> list = poliReviewInfoMapper.selectalready();
        poliReviewInfoService.exportpoli(response,list,Polialrvo.class,"已政审信息表");


    }
}
